package com.fy.module.repo.controller;

import com.fy.common.dto.PageDto;
import com.fy.common.vo.ApiRest;
import com.fy.common.vo.PageResult;
import com.fy.module.repo.entity.Repo;
import com.fy.module.repo.service.IRepoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 题库 前端控制器
 * </p>
 *
 * @author 虚拟宇宙公司
 * @since 2023-03-18
 */
@RestController
@RequestMapping("/repo")
@CrossOrigin
@Api(description = "题库管理")
public class RepoController {

    @Autowired
    private IRepoService repoService;

    @GetMapping("list")
    @ApiOperation("查询所有的题库")
    public List<Repo> findAll() {
        return repoService.list();
    }

    @PostMapping("page")
    @ApiOperation("分页查询题库")
    public PageResult<Repo> findPage(@RequestBody PageDto<Repo> pageDto) {
        PageResult<Repo> page = repoService.findPage(pageDto);
        return page;
    }

    @PostMapping("save")
    @ApiOperation("添加、修改题库")
    public ApiRest save(@RequestBody Repo repo) {
        ApiRest apiRest = repoService.saveRepo(repo);
        return apiRest;
    }

    @GetMapping("delete/{repoId}")
    @ApiOperation("题库单行数据删除")
    public ApiRest delete(@PathVariable String repoId) {
        ApiRest apiRest = repoService.deleteRepo(repoId);
        return apiRest;
    }

    @PostMapping("deleteBatch")
    @ApiOperation("题库批量删除")
    public ApiRest deleteIds(@RequestBody String[] ids) {
        ApiRest apiRest = repoService.deleteIds(ids);
        return apiRest;
    }
}
